<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 给定一个字符串 `s` ，请你找出其中不含有重复字符的 最长子串 的长度。

      var LongestSubstring = function (s) {
        let arr = []
        let maxLength = 0
        for (let i = 0; i < s.length; i++) {
          // 边遍历，边判断arr有否有这项，变量接收索引
          let index = arr.indexOf(s[i])
          if (index !== -1) {
            arr.splice(0, index + 1)
          }
          // 如果有这项，就往arr里追加
          arr.push(s.charAt(i))
          maxLength = Math.max(arr.length, maxLength)
        }
        return maxLength
      }
      console.log(LongestSubstring('abcabcbb'))
      // console.log(LongestSubstring('bbbbb'))
      // console.log(LongestSubstring('pwwkew'))
    </script>
  </body>
</html>
